/**
 * 拖动
 * @param obj 目标
 * @param e 
 * 
 * 1、dom对象与js对象的解藕
 * 2、closure 不能使用
 * 3、xxx = function(){} 此方式不提倡
 * 4、变量作用域
 * 5、循环中不得重复对变量赋值
 * 6、事件的释放
 */
function fDragging(obj, ev){ 
//        if(!e) e=window.event; 
        var e = ev || window.event;
        if(typeof(obj)=='string'){
        	obj = document.getElementById(obj);
        }
        var x=parseInt(obj.style.left); 
        var y=parseInt(obj.style.top); 
        var x_=e.clientX-x; 
        var y_=e.clientY-y; 
        if(document.addEventListener){ 
            document.addEventListener('mousemove', inFmove, true); 
            document.addEventListener('mouseup', inFup, true); 
        } else if(document.attachEvent){ 
            document.attachEvent('onmousemove', inFmove); 
            document.attachEvent('onmouseup', inFup); 
        } 
        inFstop(e);     
        inFabort(e); 
        function inFmove(e){ 
            var evt; 
            if(!e)e=window.event; 
            if(true){ 
                var op=obj.parentNode;
                var opX , opY ;
                if(op.nodeName == 'BODY'){
                	opX=parseInt(document.body.clientWidth); 
                	opY=parseInt(document.body.clientHeight); 
                }else{
	                opX=parseInt(op.style.left); 
	                opY=parseInt(op.style.top); 
                }
                if((e.clientX-x_)<0) return false; 
                else if((e.clientX-x_+obj.offsetWidth+opX)>(opX+op.offsetWidth)) return false; 
                
                if(e.clientY-y_<0) return false; 
                else if((e.clientY-y_+obj.offsetHeight+opY)>(opY+op.offsetHeight)) return false; 
            } 
        	obj.style.left=e.clientX-x_+'px'; 
        	obj.style.top=e.clientY-y_+'px'; 
            inFstop(e); 
        }
        function inFup(e){ 
            var evt; 
            if(!e)e=window.event; 
            if(document.removeEventListener){ 
                document.removeEventListener('mousemove', inFmove, true); 
                document.removeEventListener('mouseup', inFup, true); 
            } else if(document.detachEvent){ 
                document.detachEvent('onmousemove', inFmove); 
                document.detachEvent('onmouseup', inFup); 
            } 
            inFstop(e); 
        } 
        function inFstop(e){ 
            if(e.stopPropagation) return e.stopPropagation(); 
            else return e.cancelBubble=true;             
        }
        function inFabort(e){ 
            if(e.preventDefault) return e.preventDefault(); 
            else return e.returnValue=false; 
        } 
    } 